/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.pig4cloud.pigx.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.common.customize.enums.AbnormalEnum;
import com.pig4cloud.pigx.common.customize.exception.DuckweedException;
import com.pig4cloud.pigx.system.entity.Article;
import com.pig4cloud.pigx.system.entity.ArticleType;
import com.pig4cloud.pigx.system.mapper.ArticleMapper;
import com.pig4cloud.pigx.system.service.ArticleService;
import com.pig4cloud.pigx.system.service.ArticleTypeService;
import com.pig4cloud.pigx.system.vo.ArticleListVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文章列表
 *
 * @author pigx code generator
 * @date 2022-08-18 15:55:40
 */
@Service
@RequiredArgsConstructor
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

	private final ArticleTypeService articleTypeService;

	/**
	 * 根据文章类型获取文章列表
	 * @return r
	 */
	@Override
	public List<ArticleListVO> getArticleList(String type) {
		try {
			ArticleType articleType = articleTypeService.getOne(new QueryWrapper<ArticleType>() {{
				eq("name", type);
			}});
			if (articleType == null) {
				throw new DuckweedException(AbnormalEnum.MSG.SERVICE_SHUTTING_DOWN.getCode(),"Banner类型不存在");
			}
			List<ArticleListVO> bannerList = baseMapper.getArticleList(articleType.getId().toString());
			return bannerList;
		} catch (DuckweedException e) {
			throw e;
		} catch (Exception e) {
			throw new DuckweedException(AbnormalEnum.MSG.DISCONNECTED);
		}
	}



}
